package com.rljk.config.property;

import lombok.extern.slf4j.Slf4j;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Author:   YASUO
 * Date:     2018/7/23 14:58
 * Description:
 */
@Slf4j
public class UploadProperty {

    private static Properties props;
    static{
        loadProps();
    }

    synchronized static private void loadProps(){
        props = new Properties();
        InputStream in = null;

        try {
            in = UploadProperty.class.getClassLoader().getResourceAsStream("upload.properties");
            props.load(in);
        } catch (FileNotFoundException e) {
            log.error("payment.properties文件未找到");
        } catch (IOException e) {
            log.error("出现IOException");
        } finally {
            try {
                if(null != in) {
                    in.close();
                }
            } catch (IOException e) {
                log.error("payment.properties文件流关闭出现异常");
            }
        }
    }

    //读取key对应的value
    public static String get(String key){
        if(null == props) {
            loadProps();
        }
        return props.getProperty(key);
    }

}
